﻿//var $ = layui.jquery,
var slider = 0;
blogtype();
//类别导航开关点击事件
$('.category-toggle').click(function (e) {
    e.stopPropagation();    //阻止事件冒泡
    categroyIn();
});
//类别导航点击事件，用来关闭类别导航
$('.article-category').click(function () {
    categoryOut();
});
//遮罩点击事件
$('.blog-mask').click(function () {
    categoryOut();
});
$("body").delegate(".fa-times", "click", function () {
    $(".search-result").hide().empty();
    $("#searchtxt").val("");
    $(".search-icon i").removeClass("fa-times").addClass("fa-search");
});

//显示类别导航
function categroyIn() {
    $('.category-toggle').addClass('layui-hide');
    $('.article-category').unbind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend');
    $('.blog-mask').unbind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend');
    $('.blog-mask').removeClass('maskOut').addClass('maskIn');
    $('.blog-mask').removeClass('layui-hide').addClass('layui-show');
    $('.article-category').removeClass('categoryOut').addClass('categoryIn');
    $('.article-category').addClass('layui-show');
}

//隐藏类别导航
function categoryOut() {
    $('.blog-mask').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        $('.blog-mask').addClass('layui-hide');
    });
    $('.article-category').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
        $('.article-category').removeClass('layui-show');
        $('.category-toggle').removeClass('layui-hide');
    });
    $('.blog-mask').removeClass('maskIn').addClass('maskOut').removeClass('layui-show');
    $('.article-category').removeClass('categoryIn').addClass('categoryOut');
}

function blogtype() {
    $('#category li').hover(function () {
        $(this).addClass('current');
        var num = $(this).attr('data-index');
        $('.slider').css({'top': ((parseInt(num) - 1) * 40) + 'px'});
    }, function () {
        $(this).removeClass('current');
        $('.slider').css({'top': slider});
    });
    $(window).scroll(function (event) {
        var winPos = $(window).scrollTop();
        if (winPos > 750)
            $('#categoryandsearch').addClass('fixed');
        else
            $('#categoryandsearch').removeClass('fixed');
    });
};


